import React from 'react';

import { Upload, Button, Icon, message } from 'antd';

class UploadSingle extends React.Component {
	render() {
		let uploadProps = {
			name: 'file',
			action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
			headers: {
				authorization: 'authorization-text',
				userId: 'userId'
			},
			data: {
				otherField: 'field1'
			},
			onChange(info) {
				if (info.file.status !== 'uploading') {
					console.log(info.file, info.fileList);
				}
				if (info.file.status === 'done') {
					message.success(`${info.file.name} file uploaded successfully`);
				} else if (info.file.status === 'error') {
					message.error(`${info.file.name} file upload failed.`);
				}
			}
		};
		return (
			<>
				<Upload {...uploadProps}>
					<Button>
						<Icon type="upload" />
						点击上传
					</Button>
				</Upload>
			</>
		);
	}
}

export default UploadSingle;
